green=$(echo -en "\e[92m")
yellow=$(echo -en "\e[93m")
magenta=$(echo -en "\e[35m")
red=$(echo -en "\e[91m")
cyan=$(echo -en "\e[96m")
white=$(echo -en "\e[39m")
dep=(openssh-server wget curl sudo git systemctl)
local packages
 # if apt update 2>/dev/null && apt install -y openrc 2>/dev/null; then
 #          echo -e "已安openrc!"
 #     else
 #         sleep 2s
 #         sudo dpkg --configure -a
 #         if apt update 2>/dev/null && apt install -y openrc 2>/dev/null; then
 #              echo -e "已安openrc!"
 #         else
 #              echo -e "openrc安装失败!"
 #         fi
 # fi
  if apt update 2>/dev/null && apt install -y git 2>/dev/null; then
           echo -e "已安git!"
      else
          sleep 2s
          sudo dpkg --configure -a
          if apt update 2>/dev/null && apt install -y git 2>/dev/null; then
               echo -e "已安git!"
          else
               echo -e "git安装失败!"
          fi
  fi
  if ! apt-get install -y systemctl ; then
    sleep 2s
    sudo dpkg --configure -a
    if !  apt-get install -y systemctl ; then
        echo -e "安装systemctl失败!"
    else
        echo -e "已安systemctl!"
    fi
 else
    echo -e "已安systemctl!"
 fi
  echo -e "正在检查以下依赖项:"
  #检查是否安装了程序包，如果没有，请将其名称写入数组
  for pkg in "${dep[@]}"; do
    echo -e "${cyan}● ${pkg} ${white}"
    [[ ! $(dpkg-query -f'${Status}' --show "${pkg}" 2>/dev/null) = *\ installed ]] && \
    packages+=("${pkg}")
  done
  #如果数组不为空，则从数组安装程序包
  if (( ${#packages[@]} > 0 )); then
    echo -e "安装以下依赖项:"
    for package in "${packages[@]}"; do
      echo -e "${cyan}● ${package} ${white}"
    done
    if  apt-get update --allow-releaseinfo-change && apt-get install "${packages[@]}" -y; then
      echo -e "已安装依赖项!"
    else
      sudo dpkg --configure -a
      sleep 2s
      if apt-get update --allow-releaseinfo-change && apt-get install "${packages[@]}" -y; then
           echo -e "已安装依赖项!"
      else
           echo -e "安装依赖项失败!"
      fi
    fi
  else
    echo -e "已满足依赖项!"
  fi
sleep 1s
echo "nameserver 8.8.8.8 
nameserver 8.8.4.4 
nameserver 114.114.114.114 
nameserver 101.226.4.6
nameserver 123.125.81.6
nameserver 183.60.83.19
nameserver 218.30.19.40
nameserver 211.137.130.3
nameserver 221.11.1.67" >> /etc/resolv.conf
curl -s https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/setup-yuan12.sh | bash -s
sed -i '/root	ALL=(ALL:ALL) ALL/a\print3D ALL=(ALL) NOPASSWD:ALL'  /etc/sudoers
chown root:root /etc/sudo.conf -R
chmod 4755 /usr/bin/sudo
chown -R root:root /etc/sudoers.d
chown root:root /etc/sudoers

mkdir -p print3D

sleep 1s
curl -s https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/LocaleCN.sh | bash -s

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/klipper-start.sh  -O /etc/init.d/klipper &>/dev/null

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/nginxk_start.sh  -O /etc/init.d/nginxk &>/dev/null

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/KlipperScreen_start.sh  -O /etc/init.d/KlipperScreen &>/dev/null

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/KlipperScreen.sh  -O /etc/init.d/KlipperScreensh &>/dev/null

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/kliqj_start.sh  -O /etc/init.d/kliqj &>/dev/null

wget https://gitee.com/xiaoh5001/android-linux-bootstrap/raw/master/moonraker-start.sh  -O /etc/init.d/moonraker &>/dev/null

wget https://gitee.com/xiaoh5001/klipperocto4a/raw/master/scripts/ksdelay.sh  -O /root/print3D/ksdelay.sh &>/dev/null

sleep 1s
sudo chmod +x /etc/init.d/kliqj
sudo chmod 777 /etc/init.d/kliqj
sudo chmod +x /etc/init.d
sudo chmod 777 /etc/init.d
chmod +x /root/print3D/ksdelay.sh
chmod 777 /root/print3D/ksdelay.sh